package com.nandougang.blog.test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ObjectProxy {

    private static final String METHOD_PREFIX = "test";
    private Object target;

    public ObjectProxy(Object target) {
        this.target = target;
    }


    public Object getProxy() {
        return Proxy.newProxyInstance(Thread.currentThread()
                .getContextClassLoader(), target.getClass().getInterfaces(),
            new InvocationHandler() {
                @Override
                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    if (method.getName().startsWith(METHOD_PREFIX)) {
                        System.out.println("========分隔符========");
                    }
                    method.invoke(target,args);
                    return null;
                }
            });
    }


}
